/**
 * Copyright (c) 2010 XXXXX
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package ar.edu.itba.ia2010.geneticos.motor.api.impl;

import java.util.ListIterator;

import org.apache.commons.lang.Validate;

/**
 * {@link ListIterator} que no permite hacer add o removes.
 *
 * @author Juan F. Codagnone
 * @since Mar 21, 2010
 * @param <T> tipo del iterador
 */
public class OnlySetListIterator<T> implements ListIterator<T> {
    private final ListIterator<T> target;


    /** Creates the OnlySetListIterator. */
    public OnlySetListIterator(final ListIterator<T> target) {
        Validate.notNull(target);

        this.target = target;
    }

    /** @see ListIterator#add(Object) */
    public final void add(final T e) {
        throw new UnsupportedOperationException();
    }
    
    /** @see ListIterator#remove() */
    public final void remove() {
        throw new UnsupportedOperationException();
    }

    /** @see ListIterator#hasNext() */
    public final boolean hasNext() {
        return target.hasNext();
    }

    /** @see ListIterator#hasPrevious() */
    public final boolean hasPrevious() {
        return target.hasPrevious();
    }

    /** @see ListIterator#next() */
    public final T next() {
        return target.next();
    }

    /** @see ListIterator#nextIndex() */
    public final int nextIndex() {
        return target.nextIndex();
    }

    /** @see ListIterator#previous() */
    public final T previous() {
        return target.previous();
    }

    /** @see ListIterator#previousIndex() */
    public final int previousIndex() {
        return target.previousIndex();
    }

    /** @see ListIterator#set(Object) */
    public final void set(final T e) {
        if(e == null) {
            throw new IllegalArgumentException("null sett is not alowed");
        }
        target.set(e);
    }
}
